package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.EsDocService;
import com.bawei.system.domain.vo.EsDocInsertVo;
import com.bawei.system.domain.vo.EsDocQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "Es文档管理")
@RequestMapping("/esDoc")
public class EsDocController {

    @Autowired
    private EsDocService esDocService;

    @PostMapping("/batchInsertDocs")
    @ApiOperation(value = "批量插入文档")
    public R<Boolean>  batchInsertDocs(@RequestBody List<EsDocInsertVo> esDocInsertVos){
        return esDocService.batchInsertDocs(esDocInsertVos);
    }

    @PostMapping("/batchDeleteDocs")
    @ApiOperation(value = "批量删除sku文档")
    public R  batchDeleteDocs(@RequestBody ArrayList<String> list, @RequestParam String indexName){
        return esDocService.batchDeleteDocs(list,indexName);
    }

    @PostMapping("/queryDocs")
    @ApiOperation(value = "根据传入条件查询Es的文档数据")
    public R<List<Map>>  queryDocs(@RequestBody EsDocQueryVo esDocInsertVo){
        return esDocService.queryDocs(esDocInsertVo);
    }


    @GetMapping("/querySuggestions/{indexName}/{keyWord}/{suggestFiled}")
    @ApiOperation(value = "自动补全联想搜索")
    public R  querySuggestions(@PathVariable String indexName,@PathVariable("keyWord") String keyWord,@PathVariable("suggestFiled") String suggestFiled){
        return esDocService.querySuggestions(indexName,keyWord,suggestFiled);
    }

    @GetMapping("/queryDocsIndices")
    @ApiOperation(value = "查询所有索引")
    public List<String> queryDocsIndices(){
        return esDocService.queryDocsIndices();
    }


}

